#include "Engine.h"

namespace TC
{
    namespace Qml
    {
        Engine::Engine()
        {
            assert(_instance == nullptr);
            // #TODO: initialize class

            _instance = this;
        }

        Engine::~Engine()
        {
            _instance = nullptr;
        }

        Q_INVOKABLE void Engine::trim()
        {
            this->trimComponentCache();
        }

		Q_INVOKABLE void Engine::addImportPath(const QString& dir)
		{
			return QQmlApplicationEngine::addImportPath(dir);
		}

		Q_INVOKABLE void Engine::removeImoportPath(QString path)
		{
			path = path.toLower();
			QStringList paths;
			for (const auto &p : importPathList())
			{
				if (p.toLower() != path)
				{
					paths.push_back(p);
				}
			}
			setImportPathList(paths);
		}

		Engine* Engine::instance()
        {
            if (_instance == nullptr)
                _instance = new Qml::Engine;
            return _instance;
        }


        Engine* Engine::_instance = nullptr;
    }

}